<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class hocvien_db 
	{
		public function Them($MaHocVien, $MaLopHoc, $MaChuongTrinh, $MaThoiGianHoc, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $Lop, $SoMay, $NgayDangKy, $MaTrangThai, $PIN, $HocPhiDuocGiam, $HocPhiDaNop, $DaXoa)
		{
			$sql = "INSERT INTO `tbl_hocvien`(`MaHocVien`, `MaLopHoc`, `MaChuongTrinh`, `MaThoiGianHoc`, `HoTen`, `NgaySinh`, `GioiTinh`, `DiaChi`, `DienThoai`, `Email`, `Lop`, `SoMay`, `NgayDangKy`, `MaTrangThai`, `PIN`, `HocPhiDuocGiam`, `HocPhiDaNop`, `DaXoa`)
					VALUES ('$MaHocVien', '$MaLopHoc', '$MaChuongTrinh', '$MaThoiGianHoc', '$HoTen', '$NgaySinh', '$GioiTinh', '$DiaChi', '$DienThoai', '$Email', '$Lop', '$SoMay', '$NgayDangKy', '$MaTrangThai', '$PIN', '$HocPhiDuocGiam', '$HocPhiDaNop', '$DaXoa')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaHocVien)
		{
			$sql = "DELETE FROM `tbl_hocvien` WHERE `MaHocVien` = '$MaHocVien'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaHocVien, $MaLopHoc, $MaChuongTrinh, $MaThoiGianHoc, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $Lop, $SoMay, $NgayDangKy, $MaTrangThai, $PIN, $HocPhiDuocGiam, $HocPhiDaNop, $DaXoa)
		{
			$sql = "UPDATE `tbl_hocvien`
					SET `MaLopHoc` = '$MaLopHoc', `MaChuongTrinh` = '$MaChuongTrinh', `MaThoiGianHoc` = '$MaThoiGianHoc', `HoTen` = '$HoTen', `NgaySinh` = '$NgaySinh', `GioiTinh` = '$GioiTinh', `DiaChi` = '$DiaChi', `DienThoai` = '$DienThoai', `Email` = '$Email', `Lop` = '$Lop', `SoMay` = '$SoMay', `NgayDangKy` = '$NgayDangKy', `MaTrangThai` = '$MaTrangThai', `PIN` = '$PIN', `HocPhiDuocGiam` = '$HocPhiDuocGiam', `HocPhiDaNop` = '$HocPhiDaNop', `DaXoa` = '$DaXoa'
					WHERE `MaHocVien` = '$MaHocVien'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaHocVien, $MaLopHoc, $MaChuongTrinh, $MaThoiGianHoc, $HoTen, $NgaySinh, $GioiTinh, $DiaChi, $DienThoai, $Email, $Lop, $SoMay, $NgayDangKy, $MaTrangThai, $PIN, $HocPhiDuocGiam, $HocPhiDaNop, $DaXoa)
		{
			$sql = "SELECT * FROM `tbl_hocvien` WHERE 1  ";
			if($MaHocVien != "")
				$sql .= " AND `MaHocVien` = '$MaHocVien' ";

			if($MaLopHoc != "")
				$sql .= " AND `MaLopHoc` = '$MaLopHoc' ";

			if($MaChuongTrinh != "")
				$sql .= " AND `MaChuongTrinh` = '$MaChuongTrinh' ";

			if($MaThoiGianHoc != "")
				$sql .= " AND `MaThoiGianHoc` = '$MaThoiGianHoc' ";

			if($HoTen != "")
				$sql .= " AND `HoTen` = '$HoTen' ";

			if($NgaySinh != "0000-00-00")
				$sql .= " AND `NgaySinh` = '$NgaySinh' ";

			if($GioiTinh != -1)
				$sql .= " AND `GioiTinh` = '$GioiTinh' ";

			if($DiaChi != "")
				$sql .= " AND `DiaChi` = '$DiaChi' ";

			if($DienThoai != "")
				$sql .= " AND `DienThoai` = '$DienThoai' ";

			if($Email != "")
				$sql .= " AND `Email` = '$Email' ";

			if($Lop != "")
				$sql .= " AND `Lop` = '$Lop' ";

			if($SoMay != "")
				$sql .= " AND `SoMay` = '$SoMay' ";

			if($NgayDangKy != "0000-00-00")
				$sql .= " AND `NgayDangKy` = '$NgayDangKy' ";

			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = '$MaTrangThai' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			if($HocPhiDuocGiam != -1)
				$sql .= " AND `HocPhiDuocGiam` = '$HocPhiDuocGiam' ";

			if($HocPhiDaNop != -1)
				$sql .= " AND `HocPhiDaNop` = '$HocPhiDaNop' ";

			if($DaXoa != -1)
				$sql .= " AND `DaXoa` = '$DaXoa' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

